import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:paly_android/bean/wxartilce_type_entity.dart';
import 'package:paly_android/bloc/wx_article_bloc.dart';
import 'package:paly_android/ui/wxarticle_page.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class WorkPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _WorkPageState();
}

class _WorkPageState extends State<WorkPage> {
  late WxArticleBloc _wxArticleBloc;

  // late TabController _tabController;

  @override
  void initState() {
    _wxArticleBloc = WxArticleBloc();
    _wxArticleBloc.add(WxTypeEvent());
    // _tabController= TabController(length: length, vsync: vsync);
  }

  @override
  Widget build(BuildContext context) {
    return BlocProvider<WxArticleBloc>(
      create: (BuildContext context) => _wxArticleBloc,
      child: BlocBuilder<WxArticleBloc, WxArticleState>(
        builder: (context, state) {
          List<WxartilceTypeData> data = (state as WxArticleInitial).data;

          return DefaultTabController(
            length: data.length,
            child: Scaffold(
              appBar: AppBar(
                title: Row(
                  // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    Expanded(
                        child: TabBar(
                      // labelStyle: TextStyle(backgroundColor: Colors.blue,),
                      isScrollable: true,
                      tabs: data.map((e) => Tab(text: e.name)).toList(),
                    ))
                  ],
                ),
              ),
              body: TabBarView(
                children:
                    data.map((e) => WxArticlePage(e.id!.toString())).toList(),
              ),
            ),
          );
        },
      ),
    );
  }
}
